# 作者： 李泉志
# 2025年01月04日14时42分秒
# 2947029073@qq.com

# 2.变量
def variation():
    a = 66
    b = 123.123
    c = True
    d = complex(3, 4)
    e = "hello"
    f = [1, 2, 3]
    g = (1, 2, 3)
    h = {"name": "king", "age": 18}

    print("a =", a, "type(a) =", type(a))
    print("b =", b, "type(b) =", type(b))
    print("c =", c, "type(c) =", type(c))
    print("d20 =", d, "type(d20) =", type(d))
    print("e =", e, "type(e) =", type(e))
    print("f =", f, "type(f) =", type(f))
    print("g =", g, "type(g) =", type(g))
    print("h =", h, "type(h) =", type(h))


# 3.进制转换
def convert(a):
    b = bin(a)
    c = oct(a)
    d = hex(a)
    print("十进制数：", a)
    print("二进制数：", b)
    print("八进制数：", c)
    print("十六进制数：", d)


# 4.实现1-100的奇数求和
def sum_odd():
    sum = 0
    for i in range(1, 101, 2):
        sum += i
    print("1-100的奇数求和：", sum)


# 5.打印九九乘法表
def multi_table():
    for i in range(1, 10):
        for j in range(1, i + 1):
            # print(j, "x", i, "=", i * j, end="\t")
            print(f'{j}*{i} = {i * j:<2}',end=" ")  # 左对齐是<2
        print()

# 6.统计一个整数对应的二进制数的1的个数。
def bin_1():
    """
    输入一个整数（可正可负，负数就按64位去遍历即可），
    输出该整数的二进制包含1的个数（使用位运算）
    :return:
    """
    num = int(input("请输入一个整数："))
    count = 0
    if num < 0:
        for i in range(64):
            if num & 1:
                count += 1
            num >>= 1
    else:
        while num:
            if num & 1:
                count += 1
            num >>= 1
    print("二进制数中1的个数为：", count)


# variation()
# convert(256)
# sum_odd()
multi_table()
#bin_1()
